{% extends 'base.html' %}

{% block title %}编辑模型{% endblock %}

{% block content %}
<div class="row justify-content-center">
    <div class="col-md-8">
        <div class="card">
            <div class="card-header">
                <h4 class="mb-0">编辑模型</h4>
            </div>
            <div class="card-body">
                <form method="post">
                    <div class="mb-3">
                        <label for="emission_source" class="form-label">排放源 <span class="text-danger">*</span></label>
                        <input type="text" class="form-control" id="emission_source" name="emission_source" value="{{ model.emission_source }}" required>
                    </div>
                    
                    <div class="mb-3">
                        <label for="description" class="form-label">说明</label>
                        <textarea class="form-control" id="description" name="description" rows="3">{{ model.description }}</textarea>
                    </div>
                    
                    <div class="mb-3">
                        <label for="data_source" class="form-label">数据来源</label>
                        <input type="text" class="form-control" id="data_source" name="data_source" value="{{ model.data_source }}">
                    </div>
                    
                    <div class="mb-3">
                        <label for="emission_unit" class="form-label">排放源单位 <span class="text-danger">*</span></label>
                        <input type="text" class="form-control" id="emission_unit" name="emission_unit" value="{{ model.emission_unit }}" required>
                    </div>
                    
                    <div class="mb-3">
                        <label for="category_id" class="form-label">模型分类 <span class="text-danger">*</span></label>
                        <select class="form-select" id="category_id" name="category_id" required>
                            <option value="">-- 选择模型分类 --</option>
                            {% for category in categories %}
                                <option value="{{ category.id }}" {% if model.category_id == category.id %}selected{% endif %}>
                                    {{ '　' * (category.level - 1) }}|-- {{ category.name }}
                                </option>
                            {% endfor %}
                        </select>
                    </div>
                    
                    <div class="mb-3">
                        <label for="factor_id" class="form-label">碳排放因子 <span class="text-danger">*</span></label>
                        <select class="form-select" id="factor_id" name="factor_id" required>
                            <option value="">-- 选择碳排放因子 --</option>
                            {% for factor in factors %}
                                <option value="{{ factor.id }}" {% if model.factor_id == factor.id %}selected{% endif %}>
                                    {{ factor.category_path }} -> {{ factor.name }}
                                </option>
                            {% endfor %}
                        </select>
                    </div>
                    
                    <div class="d-flex justify-content-between">
                        <a href="{{ url_for('model.model_list') }}" class="btn btn-secondary">取消</a>
                        <button type="submit" class="btn btn-primary">更新</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{% endblock %}